<?php

namespace app\admin\controller;

use app\admin\controller\BaseController;
use think\Request;
use think\Validate;

class Config extends BaseController
{
    // 设置模型名称
    protected $modelName = 'config';

    protected $uniqueFields = ['name'];

    protected $fieldLabels = [
        'name' => '变量标识',
    ];

    // 设置验证规则
    // 添加自定义string验证规则
    public function __construct()
    {
        parent::__construct();
        Validate::extend('string', function ($value) {
            return is_string($value);
        }, '必须是字符串类型');
    }

    // 设置验证规则
    protected $validateRules = [
        'id' => 'number',
        'name' => 'require|max:20',
        'title' => 'require|max:20',
        'group_id' => 'require|number',
        'value' => 'require|string',
        'remark' => 'string',
    ];

    // 设置规则提示
    protected $validateRulesMsg = [
        'name.require' => '变量标识不能为空',
        'name.max' => '变量标识最多20个字符',
        'title.require' => '标题不能为空',
        'title.max' => '标题最多20个字符',
        'group_id.require' => '配置分组不能为空',
        'value.require' => '配置值不能为空',
    ];
}
